<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>投放</title>

    <link rel="shortcut icon" href="/hplus/favicon.ico">
    <link href="/hplus/css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="/hplus/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/hplus/css/animate.css" rel="stylesheet">
    <link href="/hplus/css/style.css?v=4.1.0" rel="stylesheet">
    <!-- 全局js -->
    <script src="/hplus/js/bootstrap.min.js?v=3.3.7"></script>
    <!-- 自定义js -->
    <script src="/hplus/js/content.js?v=1.0.0"></script>
    <!-- iCheck -->
    <script src="/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <!-- SUMMERNOTE -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/css/public.css" media="all">
    <style>
        img[src=""],img:not([src]){
            opacity:0;
        }
    </style>
</head>
<body>

<div class="layui-container row">
    <div class="col-sm-12 layui-form">
        <div class="ibox float-e-margins layui-form-item">
            <div class="ibox float-e-margins layui-form-item">
                <div class="ibox-title layui-form-item">
                    <h5>广告投放申请</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="ibox-content layui-form-item">
                <form class="form-horizontal ">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">封面</label>
                        <div class="form-group layui-form-item">
                            <img id="information" alt="image" class="img-responsive" width="100" height="100" src="/hplus/img/a1.jpg">
                        </div>
                    </div>

                </form>

<%--                <div class="form-group layui-form-item">--%>
<%--                    <label class="col-sm-2 control-label">投放平台</label>--%>
<%--                    <div class="col-sm-10">--%>
<%--                        <select class="form-control m-b" name="platformId" id="platformId">--%>
<%--                            <c:forEach items="${platformList}" var="list">--%>
<%--                                <option value="${list.id}">${list.name}</option>--%>
<%--                            </c:forEach>--%>
<%--                        </select>--%>
<%--                    </div>--%>
<%--                </div>--%>
                    <div class="form-group layui-form-item">
                        <label class="col-sm-2 control-label">主题</label>
                        <div class="col-sm-10">
                            <input type="text" lay-verify="required" id="theme" class="form-control" name="theme">
                        </div>
                    </div>
                    <div class="form-group layui-form-item" >
                        <label class="col-sm-2 control-label">品牌</label>
                        <div class="col-sm-10">
                            <input type="text" lay-verify="required" class="form-control" name="brand" id="brand">
                        </div>
                    </div>
                    <div class="form-group layui-form-item">
                        <label class="col-sm-2 control-label">公司链接</label>
                        <div class="col-sm-10">
                            <input type="text" lay-verify="required" class="form-control" name="compUrl" id="compUrl">
                        </div>
                    </div>
                    <div class="form-group layui-form-item">
                        <label class="col-sm-2 control-label">产品所属行业</label>
                        <div class="col-sm-10">
                            <select class="form-control m-b" name="productType" id="productType">
<%--                                <option value="">请选择</option>--%>
                                <c:forEach items="${classifies}" var="list">
                                    <option value="${list.id}">${list.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group layui-form-item">
                        <label class="col-sm-2 control-label">产品名称</label>
                        <div class="col-sm-10">
                            <input type="text" lay-verify="required" class="form-control" name="productName" id="productName">
                        </div>
                    </div>
                    <div class="form-group layui-form-item">
                        <label class="col-sm-2 control-label">产品详情链接</label>
                        <div class="col-sm-10">
                            <input type="text" lay-verify="required" class="form-control" name="productUrl" id="productUrl">
                        </div>
                    </div>

                    <div class="form-group layui-form-item">
                        <label class="col-sm-2 control-label">推广需求</label>
                        <div class="col-sm-10">
                            <div class="ibox-content no-padding">
                                <div class="summernote">
<%--                                    layui富文本编辑无显示？--%>
<%--                                    <textarea id="detail"  name="detail" style="display: none;"></textarea>--%>
                                    <textarea id="xq" name="xq"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group layui-form-item">
                        <label class="col-sm-2 control-label">资质证明</label>
                        <div class="col-sm-10">
                            <button type="button" class="layui-btn" id="test1">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                        </div>
                        <img id="demo1" name="demo1" style="width: 200px;height: 200px;margin-left: 193px;margin-top: 10px"/>

                    </div>

                    <div class="form-group layui-form-item">
<%--                        <label class="col-sm-2 control-label">推广时间</label>--%>
<%--                        <div class="col-sm-10">--%>
<%--                            <input type="text" class="layui-input" id="createTime" name="createTime" placeholder="yyyy-MM-dd">--%>
<%--                        </div>--%>
                    </div>
                    <div class="form-group layui-form-item">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-primary" type="button" lay-submit="" lay-filter="saveBtn">提交申请</button>
                            <button class="btn btn-white" type="button" id="but">返回</button>
                        </div>
                    </div>
                <input type="hidden" id="id" name="id" value="${id}">
                <input type="hidden" id="adsId" name="adsId" value="${adsId}">
            </div>
        </div>
    </div>
</div>

<script src="/layui/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','layer','element'], function () {
        var form = layui.form,
            layer = layui.layer,
            element = layui.element,
            upload = layui.upload,
            $ = layui.jquery;
        var cs = null;
        /*上传资质证明*/
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/upload' //上传接口
            ,before:function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接 (base64)
                    cs = result;
                });
            }
            ,done: function(res){
            }
            ,error: function(){
                //请求异常回调
            }
        });

        /** 提交到提交投放申请 **/
        form.on('submit(saveBtn)', function (data) {
            data = data.field;
            var xq = $("#xq").val();
            if(xq == "" || xq == null){
                layer.msg("请先填写推广需求");
                return false;
            }else if(cs == null){
                layer.msg("请先上传资质证明");
                return false;
            }

            var theme = $("#theme").val();
            // var platformId = $("#platformId").val();
            var brand = $("#brand").val();
            var compUrl = $("#compUrl").val();
            var productType = $("#productType").val();
            var productName = $("#productName").val();
            var productUrl = $("#productUrl").val();
            var id = $("#id").val();
            var adsId = $("#adsId").val();
            var strImg = $(this).find("#demo1").attr("src");
            $.ajax({
                url:"/apply",
                type:"post",
                // "detail": layedit.getContent(index),"productId":productId,
                data: {"productType": productType,"proof": cs,"detail": xq,"theme": theme,"brand":brand,
                    "compUrl":compUrl,"mediaId":id,"productName":productName,"productUrl":productUrl,
                    "price":${price},"adsId":adsId},
                dataType: 'json',
                success:function (result){
                    if (result.code == '0') {
                        layer.msg('投放成功');
                        setTimeout("window.history.go(-1)",700);
                    }else{
                        layer.msg(result.msg);
                    }
                }
            });

            return false;
        });

    });
    $(function (){
        $('#but').click(function(){
            window.history.go(-1);
        })
    })
</script>
</body>
</html>
